<template>
  <div>
    <el-card class="box-card" style="margin:20px;">
      <div slot="header" class="clearfix">
        <div class="tipText">
          <p>智育素质评分标准</p>
          <p>
            智育素质主要考察学生在学习能力、创新能力等方面的综合表现，以学生的学业成绩和创新能力成绩为测评依据。具体计算方法为：
          </p>
          <p>
            1.智育素质测评成绩(C2，60分）=学业成绩(Z1，55分)+资格证书成绩(Z2，5分)
          </p>
          <p>
            2.各类资格证书加分，最高分不超过5分。（多本同类的证书不重复加分，按最高级别加分；获得其余等级证书酌情加分）
          </p>
          <p>
            3.创新创业：加入“2+1创业班”、申请完成互联网+项目、申请成功创业园项目、自主创新创业认定，当学期加0.5分，满分0.5分。
          </p>
        </div>
      </div>
      <div>
        <avue-form
          v-if="update"
          ref="form"
          v-model="obj"
          :option="option"
          @reset-change="emptytChange"
        >
          <template slot="menuForm">
            <el-button
              icon="el-icon-edit"
              type="primary"
              @click="submit"
              v-if="butDis"
              >提 交</el-button
            >
            <el-button
              icon="el-icon-edit"
              @click="updateSub"
              type="primary"
              v-else
              >更新</el-button
            >
          </template>
        </avue-form>
      </div>
    </el-card>
  </div>
</template>
<script>
import { baseUrl } from "@/config/env";
import { httpCheck } from "@/api/studentsPage/approval";
import { willHttp } from "@/api/teacherPage/review";

var DIC = {
  VAILD: [
    { label: "2+1创业班", value: 10 },
    { label: "申请完成互联网+项目", value: 20 },
    {
      label: "申请成功创业园项目",
      value: 30
    },
    { label: "自主创新创业认定", value: 40 }
  ]
};

export default {
  data() {
    return {
      update: true,
      // 控制更新、新增按钮
      butDis: true
    };
  },
  computed: {
    option() {
      return {
        size: "mini",
        mockBtn: false,
        submitBtn: false,
        printBtn: false,
        column: [
          {
            label: "申报类型",
            prop: "type",
            type: "select",
            dicData: DIC.VAILD,
            span: 10,
            mock: {
              type: "dic"
            },
            rules: [
              {
                required: true,
                message: "请选择申报类型",
                trigger: "blur"
              }
            ]
          },
          {
            label: "申报理由",
            span: 18,
            prop: "adit",
            type: "textarea",
            mock: { type: "textarea" }
          },

          {
            label: "附件上传",
            prop: "imgUrl",

            type: "upload",
            propsHttp: {
              home: baseUrl,
              res: "data"
            },
            props: {
              value: "url",
              label: "name"
            },
            span: 24,
            listType: "picture-card",
            tip: "只能上传jpg/png文件，且不超过500kb",
            action: baseUrl + "/basic/sys-file-log/upload"
          }
        ]
      };
    }
  },
  // mounted() {
  //   this.obj = {};
  // },
  async mounted() {
    let id = this.$route.query.id;
    if (id) {
      await willHttp("innovative", id).then(res => {
        this.obj.adit = res[0].data.remark;
        this.obj.type = res[0].data.type;
        this.obj.imgUrl = res[0].data.files;
        this.butDis = false;
      });
    }
  },
  methods: {
    // 更新
    updateSub() {
      this.submitParams("update");
    },
    // 提交done
    submit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submitParams();
        } else {
          return false;
        }
      });
    },
    async submitParams(par) {
      let params = {};
      params.files = this.obj.imgUrl;
      params.remark = this.obj.adit;
      params.type = this.obj.type;
      if (par) {
        params.id = this.$route.query.id;

        httpCheck("innovative", params, "PUT").then(res => {
          if (res.code == 1) {
            this.submitFun(par);
          } else {
            this.reload();
            this.$message.error(res.message);
          }
        });
      } else {
        httpCheck("innovative", params, "POST").then(res => {
          if (res.code == 1) {
            this.submitFun();
          } else {
            this.reload();
            this.$message.error(res.message);
          }
        });
      }
    },
    submitFun(par) {
      if (par) {
        var arr = [" 更新成功", " 将在3s后自动跳转到申报详情页面"];
      } else {
        arr = [" 提交成功", " 将在3s后自动跳转到申报详情页面"];
      }
      let str = arr.join(" <br/> <br/> ");
      this.$message({
        dangerouslyUseHTMLString: true,
        message: str,
        type: "success"
      });
      setTimeout(() => {
        this.$router.push("/studentsPage");
        this.reload();
        this.emptyChange();
      }, 3000);
    },

    reload() {
      this.update = false;
      this.$nextTick(() => {
        this.update = true;
      });
    },
    // 清空方法
    emptyChange() {
      this.obj = {};
    }
  }
};
</script>
<style>
.tipText p {
  text-indent: 2em;
}
.tipText {
  border: 1px solid #455;
  height: 200px;
  overflow: auto;
  padding: 25px;
  padding-top: 0;
  font-size: 13px;
  font-weight: 300;
}
</style>
